#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QShortcut>
#include <QKeySequence>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->horizontalSlider->setMinimum(100);
    ui->horizontalSlider->setMaximum(2000);
    ui->horizontalSlider->setSingleStep(50);
    ui->horizontalSlider->setValue(800);

    ui->verticalSlider->setMinimum(100);
    ui->verticalSlider->setMaximum(1600);
    ui->verticalSlider->setSingleStep(50);
    ui->verticalSlider->setValue(600);

    QShortcut* shortCut1 = new QShortcut(this);
    QShortcut* shortCut2 = new QShortcut(this);

    shortCut1->setKey(QKeySequence("="));
    shortCut2->setKey(QKeySequence("-"));

    connect(shortCut1, &QShortcut::activated, this, &Widget::addValue);
    connect(shortCut2, &QShortcut::activated, this, &Widget::subValue);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::subValue()
{
    int value = ui->horizontalSlider->value();
    if (value <= ui->horizontalSlider->minimum())
        return;
    ui->horizontalSlider->setValue(value - 20);
}

void Widget::addValue()
{
    int value = ui->horizontalSlider->value();
    if (value >= ui->horizontalSlider->maximum())
        return;
    ui->horizontalSlider->setValue(value + 20);
}


void Widget::on_dial_valueChanged(int value)
{
    qDebug() << value;
    this->setWindowOpacity((double)value / 100);
}

void Widget::on_horizontalSlider_valueChanged(int value)
{
    QRect rect = this->geometry();
    this->setGeometry(rect.x(), rect.y(), value, rect.height());
}

void Widget::on_verticalSlider_valueChanged(int value)
{
    QRect rect = this->geometry();
    this->setGeometry(rect.x(), rect.y(), rect.width(), value);
}
